﻿namespace ufida.u9.ait.openapi
{
	using System;
	using System.Collections.Generic;
	using System.Text;
	using ufida.u9.ait.openapi.utils;
	using UFIDA.U9.Base.UserRole.Login;
	using UFIDA.U9.CBO.FI.Exceptions;
	using UFIDA.U9.PM.PM_Util;
	using UFSoft.UBF.AopFrame;
	using UFSoft.UBF.Service;
	using UFSoft.UBF.Util.Context;

	/// <summary>
	/// LoginSV partial 
	/// </summary>	
	public partial class LoginSV 
	{	
		internal BaseStrategy Select()
		{
			return new LoginSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class LoginSVImpementStrategy : BaseStrategy
	{
		public LoginSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			LoginSV bpObj = (LoginSV)obj;

			try
			{
                if (bpObj.Data == null)
                {
                    throw new Exception("传入参数为空");
                }

                LoginManager loginManager = new LoginManager();
                loginManager.Login(bpObj.Data.UserCode, bpObj.Data.Password,
                    long.Parse(PlatformContext.Current.OrgID),
                    PlatformContext.Current.Culture, "",
                    long.Parse(PlatformContext.Current.EnterpriseID));

                Guid guid = ISVSecurityService.GetNewSecurityToken(bpObj.Data.UserCode
					, bpObj.Data.Password);
				Dictionary<String,String> retmap = new Dictionary<String,String>();
				retmap.Add("token",guid.ToString());
                return ResultUtils.success(bpObj, bpObj.Data, retmap);

            }catch(Exception ex)
			{
                return ResultUtils.error(bpObj, bpObj.Data, ex);
            }
			
        }
	}





	#endregion
	
	
}